package models;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import objects.Ontology;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

/* Accessible only through OntologyModel */
class OntologyXMLWriter {
	/**
		Class is not in use.
	**/
	
	private Ontology ont;
	
	public OntologyXMLWriter() {
		ont = null;
	}

	public void setDatabase(Ontology ont) {
		this.ont = ont;
		if (this.ont == null); // TODO: just remove this useless line if ont is in use na.
	}
	
	public void write(String fileLocation) {
		Element theRoot = putXML();

		Document doc = new Document(theRoot);
		try {
			XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());
			xmlOutput.output(doc, new FileOutputStream(new File(fileLocation)));
		}
		catch (IOException e) {}
	}
	
	public Element putXML() {
		Element theRoot = new Element("ontology");
		/*
		if(ont.getOntologyList() != null) {
			for (Concept currentConcept : ont.getOntologyList() {
				Element concept = new Element("constituent");
				
				concept.setAttribute("concept", currentConcept.getName());
				concept.setAttribute("definition", currentConcept.getDefinition());
				concept.setAttribute("sense", currentConcept.getSense());
				
				theRoot.addContent(concept);
			}
		}
		*/
		return theRoot;
	}

	
	
}
